package com.lfk.justweengine.utils.io;

import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.app.Context;
import org.junit.Assert;
import org.junit.Test;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class GameIOOhosTest {

    @Test
    public void testReadAsset() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        GameIO gameIO = new GameIO(context);
        InputStream in = null;
        try {
            in = gameIO.readAsset("resources/rawfile/graphic/icon.png");
            Assert.assertEquals(-119,in.read());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testReadFile() throws IOException {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        GameIO gameIO = new GameIO(context);
        FileOutputStream outStream = (FileOutputStream) gameIO.writeFile("Text.txt");
        outStream.write("11111111111111111".getBytes());
        outStream.close();
        Assert.assertNotNull(gameIO.readFile("Text.txt"));
    }

}